﻿Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Content

Public MustInherit Class BaseSprite

    
    Public Const MoveUp = -1
    Public Const MoveDown = 1
    Public Const MoveLeft = -1
    Public Const MoveRight = 1


    Public Enum MoveMode
        UpRight
        UpLeft
        DownRight
        DownLeft
        Down
        Up
        Left
        Right
    End Enum

    Private mCurrentMoveMode As MoveMode = MoveMode.DownLeft
    Public Property CurrentMoveMode As MoveMode
        Get
            Return mCurrentMoveMode
        End Get
        Set(ByVal value As MoveMode)
            mCurrentMoveMode = value
        End Set
    End Property

    Public MustOverride ReadOnly Property SpriteName As String

    Private mSpriteTexture As Texture2D
    Public Property SpriteTexture As Texture2D
        Get
            Return mSpriteTexture
        End Get
        Set(ByVal value As Texture2D)
            mSpriteTexture = value
        End Set
    End Property

    Private mPosition As New Vector2(0, 0)
    Public Property Position As Vector2
        Get
            Return mPosition
        End Get
        Set(ByVal value As Vector2)
            mPosition = value
        End Set
    End Property

    Private mGraphicsDevice As GraphicsDevice
    Public Property GraphicsDevice As GraphicsDevice
        Get
            Return mGraphicsDevice
        End Get
        Set(ByVal value As GraphicsDevice)
            mGraphicsDevice = value
        End Set
    End Property

    Private mScale As Decimal = 1
    Public Property Scale As Decimal
        Get
            Return mScale
        End Get
        Set(ByVal value As Decimal)
            mScale = value
        End Set
    End Property

    Public ReadOnly Property Size As Rectangle
        Get
            If mSpriteTexture Is Nothing Then
                Return New Rectangle(0, 0, 0, 0)
            End If
            Return New Rectangle(0, 0, mSpriteTexture.Width * Scale, mSpriteTexture.Height * Scale)
        End Get
    End Property

    Public Sub New()
    End Sub

    Public Overridable Sub Load(ByVal currentContentManager As ContentManager, ByVal theGraphicsDevice As GraphicsDevice)
        SpriteTexture = currentContentManager.Load(Of Texture2D)(SpriteName)
        GraphicsDevice = theGraphicsDevice
    End Sub

    Public Sub Draw(ByVal currentGameTime As GameTime, ByVal currentSpriteBatch As SpriteBatch)
        currentSpriteBatch.Draw(SpriteTexture, Position, New Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), Color.White, 0, Vector2.Zero, Scale, SpriteEffects.None, 0)
    End Sub

    Public Sub MoveTo(ByVal x As Integer, ByVal y As Integer)
        Position = New Vector2(x, y)
    End Sub

    Public Sub Move(ByVal theGameTime As GameTime, ByVal theSpeed As Vector2, ByVal theDirection As Vector2)
        Position += theDirection * theSpeed * theGameTime.ElapsedGameTime.TotalSeconds
    End Sub

End Class
